package com.amigo.online.provider.adv.util;

/**
 * 广告投放用户年龄区间
 * 无年龄用户按照 0-18 区间来算
 *
 * @author Administrator
 */
public enum AgeEnum {
    //不在范围内
    AGE_0_TO_200("0-17", 0), AGE_18_TO_23("18-23", 1), AGE_24_TO_40("24-40", 2), AGE_40_TO_200("40-200", 3);

    private String ageRange;
    private int type;

    private AgeEnum(String ageRange, int type) {
        this.ageRange = ageRange;
        this.type = type;
    }

    public static int getAgeType(Long age) {
        if (age != null) {
            for (AgeEnum temp : AgeEnum.values()) {
                String[] ages = temp.ageRange.split("-");
                if (Integer.parseInt(ages[0]) <= age && (Integer.parseInt(ages[1]) >= age)) {
                    return temp.type;
                }
            }
        }
        return AgeEnum.AGE_0_TO_200.type;
    }
}
